package com.lb.shopguide.ui.view;


import android.content.Context;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lb.shopguide.R;
import com.lb.shopguide.entity.GuideStepBean;

/**
 * Created by kang on 2018/1/19.
 */

public class LbGuideStepLayout extends LinearLayout {
    private TextView tvStepName;
    private TextView tvStepContent;
    private RelativeLayout layoutContent;

    private GuideStepBean guideStepBean;

    private Context mContext;

    public LbGuideStepLayout(Context context) {
        super(context);
        LayoutInflater.from(context).inflate(R.layout.layout_guide_step, this);
        tvStepName = findViewById(R.id.tv_step_name);
        tvStepContent = findViewById(R.id.tv_step_content);
        layoutContent = findViewById(R.id.layout_step_content);
    }

    public LbGuideStepLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public void setContent(GuideStepBean bean, int process) {
        guideStepBean = bean;
        tvStepName.setText(bean.getStepName() + "：" + bean.getStepTitle());
        tvStepContent.setText(bean.getStepDesc());
        if (guideStepBean.getId() == process) {
            tvStepName.setTextColor(Color.rgb(38,38,38));
            tvStepContent.setTextColor(Color.rgb(133,133,133));
            enableClick();
        }else{
            tvStepName.setTextColor(Color.rgb(217,217,217));
            tvStepContent.setTextColor(Color.rgb(217,217,217));
        }

    }

    private void enableClick() {
        layoutContent.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (guideStepBean != null) {
                    mOnStepClickListener.onStepClick(guideStepBean);
                }
            }
        });
    }

    public interface OnStepClickListener {
        void onStepClick(GuideStepBean bean);
    }

    private OnStepClickListener mOnStepClickListener;

    public void setOnStepClickListener(OnStepClickListener listener) {
        this.mOnStepClickListener = listener;
    }
}
